local xiongzhu = fk.CreateSkill {
  name = "lingling__xiongzhu",
}

Fk:loadTranslationTable{
  ["lingling__xiongzhu"] = "雄逐",
  [":lingling__xiongzhu"] = "回合结束时，若中央区有坐骑牌，你可以获得其中一张坐骑牌。若弃牌堆有坐骑牌，你可以摸一张牌。"..
  "若你装备区有坐骑牌，你可以将一张牌当【杀】使用。",

  ["#lingling__xiongzhu-prey"] = "雄逐：你可以获得其中一张牌",
  ["#lingling__xiongzhu-draw"] = "雄逐：你可以摸一张牌",
  ["#lingling__xiongzhu-slash"] = "雄逐：你可以将一张牌当【杀】使用",
}

xiongzhu:addEffect(fk.TurnEnd, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(xiongzhu.name) and
      table.find(table.connect(player.room:getBanner("@$CenterArea"), player.room.discard_pile, player:getCardIds("e")), function (id)
        return table.contains({Card.SubtypeOffensiveRide, Card.SubtypeDefensiveRide}, Fk:getCardById(id).sub_type)
      end)
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = table.filter(room:getBanner("@$CenterArea"), function (id)
      return table.contains({Card.SubtypeOffensiveRide, Card.SubtypeDefensiveRide}, Fk:getCardById(id).sub_type)
    end)
    if #cards > 0 then
      local card = room:askToChooseCards(player, {
        target = player,
        min = 0,
        max = 1,
        flag = { card_data = {{ "@$CenterArea", cards }} },
        skill_name = xiongzhu.name,
        prompt = "#lingling__xiongzhu-prey",
      })
      if #card > 0 then
        room:moveCardTo(card, Card.PlayerHand, player, fk.ReasonJustMove, xiongzhu.name, nil, true, player)
        if player.dead then return end
      end
    end
    if table.find(room.discard_pile, function (id)
      return table.contains({Card.SubtypeOffensiveRide, Card.SubtypeDefensiveRide}, Fk:getCardById(id).sub_type)
    end) and
      room:askToSkillInvoke(player, {
        skill_name = xiongzhu.name,
        prompt = "#lingling__xiongzhu-draw",
      }) then
      player:drawCards(1, xiongzhu.name)
      if player.dead then return end
    end
    if table.find(player:getCardIds("e"), function (id)
      return table.contains({Card.SubtypeOffensiveRide, Card.SubtypeDefensiveRide}, Fk:getCardById(id).sub_type)
    end) then
      room:askToUseVirtualCard(player, {
        name = "slash",
        skill_name = xiongzhu.name,
        prompt = "#lingling__xiongzhu-slash",
        cancelable = true,
        extra_data = {
          bypass_times = true,
          extraUse = true,
        },
        card_filter = {
          n = 1,
        },
      })
    end
  end,
})

xiongzhu:addAcquireEffect(function (self, player, is_start)
  player.room:addSkill("#CenterArea")
end)

return xiongzhu
